package cn.stylefeng.guns.sys.modular.system.controller;

import cn.stylefeng.guns.base.auth.context.LoginContextHolder;
import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.sys.modular.system.entity.BtyCWGainLoss;
import cn.stylefeng.guns.sys.modular.system.service.BtyCWGainLossService;
import cn.stylefeng.guns.sys.modular.system.warpper.NoticeWrapper;
import cn.stylefeng.roses.core.base.controller.BaseController;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/btyCW")
public class BtyCWGainLossController extends BaseController {

    private String PREFIX = "/modular/system/btyCW/";

    @Autowired
    private BtyCWGainLossService btyCWGainLossService;

    /**
     * 跳转到损益表页面
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "btyCWsunyi.html";
    }

    /**
     * 跳转到资产负债表页面
     */
    @RequestMapping("/fuzhai")
    public String fuzhai() {
        return PREFIX + "btyCWfuzhai.html";
    }

    /**
     * 获取损益列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(BtyCWGainLoss btyCWGainLoss) {
        //获取用户的姓名
        String account = LoginContextHolder.getContext().getUser().getName();
        List<String> roleNames = LoginContextHolder.getContext().getUser().getRoleNames();
        Page<Map<String, Object>> list =new Page<>();
        if (account.equals("admin")|roleNames.contains("财务主管")) {
            list =btyCWGainLossService.list(btyCWGainLoss);
        }else if (roleNames.contains("会计")) {
            btyCWGainLoss.setKj(account);
            list = btyCWGainLossService.list(btyCWGainLoss);
        }else if(roleNames.contains("店长报销单管理")){
            btyCWGainLoss.setDz(account);
            list =btyCWGainLossService.list(btyCWGainLoss);
        }else if (roleNames.contains("督导")) {
            btyCWGainLoss.setDd(account);
            list = btyCWGainLossService.list(btyCWGainLoss);
        }
        Page<Map<String, Object>> wrap = new NoticeWrapper(list).wrap();
        return LayuiPageFactory.createPageInfo(wrap);
    }

    /**
     * 获取损益列表(不分页)
     */
    @RequestMapping(value = "/listAll")
    @ResponseBody
    public Object listAll(BtyCWGainLoss btyCWGainLoss) {
        return this.btyCWGainLossService.listAll(btyCWGainLoss);
    }

    /**
     * 导入损益表excel
     */

    @RequestMapping("/import")
    @ResponseBody
    public Object importExcel(@RequestParam("file") MultipartFile file) throws Exception {
        String fileName = file.getOriginalFilename();
        return this.btyCWGainLossService.importExcel(fileName,file);
    }

    /**
     * 导入资产负债excel
     */

    @RequestMapping("/importZCFZ")
    @ResponseBody
    public Object importZCFZ(@RequestParam("file") MultipartFile file) throws Exception {
        String fileName = file.getOriginalFilename();
        return this.btyCWGainLossService.importZCFZ(fileName,file);
    }


}
